class Wzq extends Board {
  constructor(dom) {
    super(dom);
    this.chessBoard = this.initChessBoard();
    this.wins = [];
    this.blackWin = [];
    this.whiteWin = [];
    this.winCount = 0;
    this.onsuccess = function () { };
    for (var i = 0; i < this.ROAD_NUM; i++) {
      this.wins[i] = [];
      for (var j = 0; j < this.ROAD_NUM; j++) {
        this.wins[i][j] = [];
      }
    }

    for (var i = 0; i < this.ROAD_NUM; i++) {
      for (var j = 0; j < (this.ROAD_NUM - this.FIVE_NUM + 1); j++) {
        for (var k = 0; k < this.FIVE_NUM; k++) {
          this.wins[i][j + k][this.winCount] = true;
        }
        this.winCount++;
      }
    }

    for (var i = 0; i < this.ROAD_NUM; i++) {
      for (var j = 0; j < (this.ROAD_NUM - this.FIVE_NUM + 1); j++) {
        for (var k = 0; k < this.FIVE_NUM; k++) {
          this.wins[j + k][i][this.winCount] = true;
        }
        this.winCount++;
      }
    }

    for (var i = 0; i < (this.ROAD_NUM - this.FIVE_NUM + 1); i++) {
      for (var j = 0; j < (this.ROAD_NUM - this.FIVE_NUM + 1); j++) {
        for (var k = 0; k < this.FIVE_NUM; k++) {
          this.wins[i + k][j + k][this.winCount] = true;
        }
        this.winCount++;
      }
    }

    for (var i = 0; i < (this.ROAD_NUM - this.FIVE_NUM + 1); i++) {
      for (var j = 18; j > 3; j--) {
        for (var k = 0; k < this.FIVE_NUM; k++) {
          this.wins[i + k][j - k][this.winCount] = true;
        }
        this.winCount++;
      }
    }

    for (var i = 0; i < this.winCount; i++) {
      this.blackWin[i] = 0;
      this.whiteWin[i] = 0;
    }
  }
  FAIL_COUNT = 99;
  FIVE_NUM = 5;


  initChessBoard() {
    var chessBoard = [];
    for (var i = 0; i < this.ROAD_NUM; i++) {
      chessBoard[i] = [];
      for (var j = 0; j < this.ROAD_NUM; j++) {
        chessBoard[i][j] = this.NULL_CHESS;
      }
    }
    return chessBoard;
  };

  getChessBoard() {
    return this.chessBoard;
  };

  getWins() {
    return this.wins;
  }

  getOneWins(type) {
    if (type === this.BLACK_COLOR) {
      return this.blackWin;
    } else if (type === this.WHITE_COLOR) {
      return this.whiteWin;
    }
  }

  getCount() {
    return this.winCount;
  }

  clear() {
    this.chessBoard = this.initChessBoard();
    this.blackWin = [];
    this.whiteWin = [];
  }

  readStep(x, y, type) {
    var isOver = true;
    for (var i = 0; i < this.winCount; i++) {
      if (this.wins[x][y][i] && this.chessBoard[x][y] === this.NULL_CHESS) {
        isOver = false;
        if (type === this.BLACK_COLOR) {
          this.blackWin[i]++;
          this.whiteWin[i] = this.FAIL_COUNT;
        } else if (type === this.WHITE_COLOR) {
          this.blackWin[i] = this.FAIL_COUNT;
          this.whiteWin[i]++;
        }
        if (this.whiteWin[i] === this.FIVE_NUM) {
          this.onsuccess(x, y, type);
        }
        if (this.blackWin[i] === this.FIVE_NUM) {
          this.onsuccess(x, y, type);
        }
      }
    }
    if (isOver) {
      this.onsuccess(0, 0, 'O');
    }
    this.chessBoard[x][y] = type;
    this.drawOneStep(x, y, type);
  }
};